package com.ljc.util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTCreator;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;

import java.util.Calendar;
import java.util.Map;

public class JWTUtil {
    private static String SIGN="!2#3#4$%5SatcadsF35";
    
    public static String getToken(Map<String,String> map){
        JWTCreator.Builder builder = JWT.create();
        String token=null;
        map.forEach((k,v)->{
            builder.withClaim(k,v);
        });
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE,1);
        builder.withExpiresAt(calendar.getTime());
        token  = builder.sign(Algorithm.HMAC256(SIGN));
        return token;
    }
    public static DecodedJWT getTokenInfo(String token){

        JWTVerifier build = JWT.require(Algorithm.HMAC256(SIGN)).build();
        DecodedJWT verify = build.verify(token);
        return verify;
    }

}
